﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Libraries.Common
{
    public static class ExtensionMethods
    {
        public static string ToStringOrDefault(this object value)
        {
            if (value == DBNull.Value || value == null)
                return string.Empty;
            return Convert.ToString(value).Trim();
        }

        public static int ToInt32OrDefault(this object value)
        {
            if (value == DBNull.Value || value == null)
                return 0;
            return Convert.ToInt32(value);
        }

        public static DateTime ToDateTimeOrDefault(this object value) 
        {
            if (value == DBNull.Value || value == null)
                return new DateTime();
            return Convert.ToDateTime(value);
        }

        public static DateTime? ToDateTimeOrNull(this object value)
        {
            if (value == DBNull.Value || value == null)
                return null;
            return Convert.ToDateTime(value);
        }
    }
}
